package com.pactera.madp.cp.service.sync.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pactera.madp.cp.api.entity.sync.MaYesterdayDataBoardEntity;
import com.pactera.madp.cp.api.vo.employee.ProductLikeVo;
import com.pactera.madp.cp.mapper.sync.MaYesterdayDataBoardMapper;
import com.pactera.madp.cp.service.sync.MaYesterdayDataBoardService;
import org.springframework.stereotype.Service;

/**
 * @title 经理视图 -> 数据看板 业务接口实现
 * @date 2022-05-12
 * @author Deming.Chang
 */
@Service
public class MaYesterdayDataBoardServiceImpl extends ServiceImpl<MaYesterdayDataBoardMapper, MaYesterdayDataBoardEntity> implements MaYesterdayDataBoardService {

    @Override
    public ProductLikeVo prodLike(String wxUserId, Integer dateType) {
        ProductLikeVo vo = new ProductLikeVo();
        MaYesterdayDataBoardEntity entity = this.getOne(
                Wrappers.<MaYesterdayDataBoardEntity>lambdaQuery()
                        .eq(MaYesterdayDataBoardEntity::getRecommendId, wxUserId), false
        );
        if (entity == null) {
            vo.setCredit(0L);
            vo.setDeposit(0L);
            vo.setFinancial(0L);
            vo.setFund(0L);
            vo.setLoan(0L);
            return vo;
        }
        // dateType == 1，查近七日数据；否则查近3日数据
        if (dateType != null && dateType == 1) {
            vo.setCredit(entity.getYesterdaySevenDaysCreditBrowses());
            vo.setDeposit(entity.getYesterdaySevenDaysDepositBrowses());
            vo.setFinancial(entity.getYesterdaySevenDaysFinancialBrowses());
            vo.setFund(entity.getYesterdaySevenDaysFundBrowses());
            vo.setLoan(entity.getYesterdaySevenDaysLoanBrowses());
        } else {
            vo.setCredit(entity.getYesterdayThreeDaysCreditBrowses());
            vo.setDeposit(entity.getYesterdayThreeDaysDepositBrowses());
            vo.setFinancial(entity.getYesterdayThreeDaysFinancialBrowses());
            vo.setFund(entity.getYesterdayThreeDaysFundBrowses());
            vo.setLoan(entity.getYesterdayThreeDaysLoanBrowses());
        }
        return vo;
    }

}
